﻿using DevExpress.XtraGrid.Views.BandedGrid;
using DLL;
using NursingFormSystem.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NursingFormSystem.HandoverSlip
{
    public partial class HandoverSingHistory : Form
    {
        #region 变量声明
        public NursingFormSystem.NurFormsService.NursingForm formService = new NursingFormSystem.NurFormsService.NursingForm();
        string[] user;
        string[] patientinfo;
        string FormName;
        string FormId;
        #endregion
        public HandoverSingHistory(string[] UserParam, string[] patientInfo, string FormName, string FormID)
        {
            InitializeComponent();
            user = UserParam;
            this.patientinfo = patientInfo;
            this.FormName = FormName;
            this.FormId = FormID;
            LoadData("", "");
            SetBandGridView();
            dateStart.Properties.DisplayFormat.FormatString = "yyyy-MM-dd";
            dateStart.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
            dateStart.Text = DateTime.Now.ToString("yyyy-MM") + "-01";
            dateEnd.Properties.DisplayFormat.FormatString = "yyyy-MM-dd";
            dateEnd.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
            dateEnd.Text = DateTime.Now.ToString("yyyy-MM-dd");
        }

        private void LoadData(string StatDate, string EndDate)
        {
            string patientid = this.patientinfo[0].ToString();//住院号
            int VisitId = Convert.ToInt32(patientinfo[1]);//住院次数
            int FormId = (int)FormType.PatientHandover;//11001  //表单ID
            string select_sql = @"SELECT  * ,                                    
SUBSTRING(' ', 1, 10) AS RiQi ,
'' AS SQZD,
'' AS NSSMC,
'' AS Ru_YiShi1,
'' AS Ru_YiShi2,
'' AS Ru_YiShi3,
'' AS Ru_TSGR1,
'' AS Ru_TSGR2,
'' AS Ru_TSGR3,
'' AS Ru_TSGR4,
'' AS Ru_TSGR5,
'' AS Ru_TiWen,
'' AS Ru_MaiBo,
'' AS Ru_HuXi,
'' AS Ru_XueYa1,
'' AS Ru_XueYa2,
'' AS Ru_WanDai1,
'' AS Ru_WanDai2,
'' AS Ru_SSBWBS1,
'' AS Ru_SSBWBS2,
'' AS Ru_BeiPi1,
'' AS Ru_BeiPi2,
'' AS Ru_GengYi1,
'' AS Ru_GengYi2,
'' AS Ru_XZQBQ2,
'' AS Ru_XZQBQ1,
'' AS Ru_ZhiRuWu2,
'' AS Ru_ZhiRuWu1,
'' AS Ru_YiChi1,
'' AS Ru_YiChi2,
'' AS Ru_YiChi3,
'' AS Ru_SSSW1,
'' AS Ru_SSSW2,
'' AS Ru_SSSWMC,
'' AS Ru_SSSWJS,
'' AS Ru_XDWP1,
'' AS Ru_XDWP2,
'' AS Ru_XDWP3,
'' AS Ru_XDWP4,
'' AS Ru_XDWP5,
'' AS Ru_XDWPMC,
'' AS Ru_YWGMS1,
'' AS Ru_YWGMS2,
'' AS Ru_YWGMSMC,
'' AS Ru_JMTL1,
'' AS Ru_JMTL2,
'' AS Ru_JMTL3,
'' AS Ru_JMTL4,
'' AS Ru_JMTL5,
'' AS Ru_SQLZ1,
'' AS Ru_SQLZ2,
'' AS Ru_SQLZ3,
'' AS Ru_SQLZ4,
'' AS Ru_SQLZMC,
'' AS Ru_PFQK1,
'' AS Ru_PFQK2,
'' AS Ru_PFQK3,
'' AS Ru_PFQKMC,
'' AS Ru_JieBingRenShiJian,
'' AS Ru_HZQX1,
'' AS Ru_HZQX2,
'' AS Ru_HZQX3,
'' AS Ru_HSQM,
'' AS Ru_SSSHSQM,
'' AS Chu_YiShi1,
'' AS Chu_YiShi2,
'' AS Chu_YiShi3,
'' AS Chu_WanDai1,
'' AS Chu_WanDai2,
'' AS Chu_XDWP1,
'' AS Chu_XDWP2,
'' AS Chu_XDWP3,
'' AS Chu_XDWP4,
'' AS Chu_XDWPMC,
'' AS Chu_SSSW1,
'' AS Chu_SSSW2,
'' AS Chu_SSSWMC,
'' AS Chu_SSSWJS,
'' AS Chu_XueZiPin1,
'' AS Chu_XueZiPin2,
'' AS Chu_XueZiPinMC,
'' AS Chu_JMTL1,
'' AS Chu_JMTL2,
'' AS Chu_JMTL3,
'' AS Chu_JMTL4,
'' AS Chu_JMTL5,
'' AS Chu_SHLZ1,
'' AS Chu_SHLZ2,
'' AS Chu_SHLZ3,
'' AS Chu_SHLZ4,
'' AS Chu_SHLZ5,
'' AS Chu_SHLZMC,
'' AS Chu_PFQK1,
'' AS Chu_PFQK2,
'' AS Chu_PFQK3,
'' AS Chu_PFQKMC,
'' AS Chu_HZQX1,
'' AS Chu_HZQX2,
'' AS Chu_HZQX3,
'' AS Chu_SSSHSQM,
'' AS Chu_HSQM,
'' AS PACU_YiShi1,
'' AS PACU_YiShi2,
'' AS PACU_YiShi3,
'' AS PACU_MaiBo,
'' AS PACU_XueYa1,
'' AS PACU_XueYa2,
'' AS PACU_XYBHD,
'' AS PACU_WanDai1,
'' AS PACU_WanDai2,
'' AS PACU_XDWP1,
'' AS PACU_XDWP2,
'' AS PACU_XDWP3,
'' AS PACU_XDWP4,
'' AS PACU_XDWPMC,
'' AS PACU_SSSW1,
'' AS PACU_SSSW2,
'' AS PACU_SSSWMC,
'' AS PACU_SSSWJS,
'' AS PACU_XueZiPin1,
'' AS PACU_XueZiPin2,
'' AS PACU_XueZiPinMC,
'' AS PACU_JMTL1,
'' AS PACU_JMTL2,
'' AS PACU_JMTL3,
'' AS PACU_JMTL4,
'' AS PACU_JMTL5,
'' AS PACU_PCABeng1,
'' AS PACU_PCABeng2,
'' AS PACU_PCABengTJ1,
'' AS PACU_PCABengTJ2,
'' AS PACU_SHLZ1,
'' AS PACU_SHLZ2,
'' AS PACU_SHLZ3,
'' AS PACU_SHLZMC,
'' AS PACU_PFQK1,
'' AS PACU_PFQK2,
'' AS PACU_PFQK3,
'' AS PACU_PFQKMC,
'' AS PACU_HZQX1,
'' AS PACU_HZQX2,
'' AS PACU_PACUYSQM,
'' AS PACU_HSQM ,

'' AS Ru_JieBingRenShiJian,
'' AS Chu_ChuShouShuShiShiJian,
'' AS PACU_ChuPACUShiJain
                              
                            FROM    dbo.NursingFormRecord 
                            WHERE   FormId = {0} 
                                    AND patientid = '{1}' 
                                    AND VisitId = {2} {3} 
                            ORDER BY [AssessmentDate] DESC";

            string whereList = string.Empty;
            if (StatDate != "" && EndDate != "")
            {
                StatDate += " 00:00:00";
                EndDate += " 00:00:00";
                whereList = string.Format(" AND [AssessmentDate]>=CONVERT(DATETIME,'{0}') AND  [AssessmentDate]<CONVERT(DATETIME,'{1}')", StatDate, 
                    Convert.ToDateTime(EndDate).AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"));
            }
            select_sql = string.Format(select_sql, FormId, patientid, VisitId, whereList);
            DataTable dt = (SqlHelper.ExecuteDataset(select_sql, CommandType.Text)).Tables[0];
            DataTable dtt = dt.Clone();
            string theTrue = "√";
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    var NursingFormData = Convert.ToString(dr["NursingFormData"]);
                    PatientHandover fd = new PatientHandover();
                    fd = XmlUtil.XMLToObject<PatientHandover>(NursingFormData, Encoding.UTF8);
                    DataRow newRow = dtt.NewRow();
                    newRow["SQZD"] = fd.ShuQianZhenDuan;
                    newRow["NSSMC"] = fd.NiShouShuMingCheng;
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.YiShi))
                    {
                        newRow["Ru_YiShi1"] = fd.RuShouShuShi.YiShi.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_YiShi2"] = fd.RuShouShuShi.YiShi.Equals("1") ? theTrue : string.Empty;
                        newRow["Ru_YiShi3"] = fd.RuShouShuShi.YiShi.Equals("2") ? theTrue : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.TeShuGanRan))
                    {
                        string ru_teshuganran = fd.RuShouShuShi.TeShuGanRan.IndexOf("#") < 0 ? "0#0#0#0#0" : fd.RuShouShuShi.TeShuGanRan;
                        string[] ru_teshuganranArray = ru_teshuganran.Split('#');
                        if (ru_teshuganranArray.Length >= 5)
                        {
                            newRow["Ru_TSGR1"] = ru_teshuganranArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_TSGR2"] = ru_teshuganranArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_TSGR3"] = ru_teshuganranArray[2].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_TSGR4"] = ru_teshuganranArray[3].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_TSGR5"] = ru_teshuganranArray[4].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    newRow["Ru_TiWen"] = fd.RuShouShuShi.TiWen;
                    newRow["Ru_MaiBo"] = fd.RuShouShuShi.MaiBo;
                    newRow["Ru_HuXi"] = fd.RuShouShuShi.HuXi;
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.XueYa))
                    {
                        string ru_xueya = fd.RuShouShuShi.XueYa.IndexOf("/") < 0 ? "0/0" : fd.RuShouShuShi.XueYa;
                        string[] ru_xueyaArray = ru_xueya.Split('/');
                        if (ru_xueyaArray.Length >= 2)
                        {
                            newRow["Ru_XueYa1"] = ru_xueyaArray[0];
                            newRow["Ru_XueYa2"] = ru_xueyaArray[1];
                        }
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.WanDai))
                    {
                        newRow["Ru_WanDai1"] = fd.RuShouShuShi.WanDai.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_WanDai2"] = fd.RuShouShuShi.WanDai.Equals("1") ? theTrue : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.ShouShuBuWeiBiaoShi))
                    {
                        newRow["Ru_SSBWBS1"] = fd.RuShouShuShi.ShouShuBuWeiBiaoShi.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_SSBWBS2"] = fd.RuShouShuShi.ShouShuBuWeiBiaoShi.Equals("1") ? theTrue : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.BeiPi))
                    {
                        newRow["Ru_BeiPi1"] = fd.RuShouShuShi.BeiPi.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_BeiPi2"] = fd.RuShouShuShi.BeiPi.Equals("1") ? theTrue : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.GenYi))
                    {
                        newRow["Ru_GengYi1"] = fd.RuShouShuShi.GenYi.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_GengYi2"] = fd.RuShouShuShi.GenYi.Equals("1") ? theTrue : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.XinZangQiBoQi))
                    {
                        newRow["Ru_XZQBQ2"] = fd.RuShouShuShi.XinZangQiBoQi.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_XZQBQ1"] = fd.RuShouShuShi.XinZangQiBoQi.Equals("1") ? theTrue : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.ZhiRuWu))
                    {
                        newRow["Ru_ZhiRuWu2"] = fd.RuShouShuShi.ZhiRuWu.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_ZhiRuWu1"] = fd.RuShouShuShi.ZhiRuWu.Equals("1") ? theTrue : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.YiChi))
                    {
                        newRow["Ru_YiChi1"] = fd.RuShouShuShi.YiChi.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_YiChi2"] = fd.RuShouShuShi.YiChi.Equals("1") ? theTrue : string.Empty;
                        newRow["Ru_YiChi3"] = fd.RuShouShuShi.YiChi.Equals("2") ? theTrue : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.SuiShenShiWu))
                    {
                        newRow["Ru_SSSW1"] = fd.RuShouShuShi.SuiShenShiWu.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_SSSW2"] = fd.RuShouShuShi.SuiShenShiWu.Equals("1") ? theTrue : string.Empty;
                    }
                    newRow["Ru_SSSWMC"] = fd.RuShouShuShi.SSSW_MingCheng;
                    newRow["Ru_SSSWJS"] = fd.RuShouShuShi.SSSW_JianShu;
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.XieDaiWuPin))
                    {
                        string ru_xiedaiwupin = fd.RuShouShuShi.XieDaiWuPin.IndexOf("#") < 0 ? "0#0#0#0#0" : fd.RuShouShuShi.XieDaiWuPin;
                        string[] ru_xiedaiwupinArray = ru_xiedaiwupin.Split('#');
                        if (ru_xiedaiwupinArray.Length >= 5)
                        {
                            newRow["Ru_XDWP1"] = ru_xiedaiwupinArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_XDWP2"] = ru_xiedaiwupinArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_XDWP3"] = ru_xiedaiwupinArray[2].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_XDWP4"] = ru_xiedaiwupinArray[3].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_XDWP5"] = ru_xiedaiwupinArray[4].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.XDWP_QiTa))
                    {
                        newRow["Ru_XDWPMC"] = fd.RuShouShuShi.XDWP_QiTa;
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.SuiShenShiWu))
                    {
                        newRow["Ru_YWGMS1"] = fd.RuShouShuShi.YaoWuGuoMinShi.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_YWGMS2"] = fd.RuShouShuShi.YaoWuGuoMinShi.Equals("1") ? theTrue : string.Empty;
                    }
                    newRow["Ru_YWGMSMC"] = fd.RuShouShuShi.YWGMS_QiTa;
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.JingMaiTongLu))
                    {
                        string ru_jingmaitonglu = fd.RuShouShuShi.JingMaiTongLu.IndexOf("#") < 0 ? "0#0#0#0#0" : fd.RuShouShuShi.JingMaiTongLu;
                        string[] ru_jingmaitongluArray = ru_jingmaitonglu.Split('#');
                        if (ru_jingmaitongluArray.Length >= 5)
                        {
                            newRow["Ru_JMTL1"] = ru_jingmaitongluArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_JMTL2"] = ru_jingmaitongluArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_JMTL3"] = ru_jingmaitongluArray[2].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_JMTL4"] = ru_jingmaitongluArray[3].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_JMTL5"] = ru_jingmaitongluArray[4].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.ShuQianLiuZhi))
                    {
                        string ru_shuqianliuzhi = fd.RuShouShuShi.ShuQianLiuZhi.IndexOf("#") < 0 ? "0#0#0#0" : fd.RuShouShuShi.ShuQianLiuZhi;
                        string[] ru_shuqianliuzhiArray = ru_shuqianliuzhi.Split('#');
                        if (ru_shuqianliuzhiArray.Length >= 4)
                        {
                            newRow["Ru_SQLZ1"] = ru_shuqianliuzhiArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_SQLZ2"] = ru_shuqianliuzhiArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_SQLZ3"] = ru_shuqianliuzhiArray[2].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_SQLZ4"] = ru_shuqianliuzhiArray[3].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    newRow["Ru_SQLZMC"] = fd.RuShouShuShi.SQLZ_MingCheng;
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.PiFuQingKuang))
                    {
                        string ru_pfqk = fd.RuShouShuShi.PiFuQingKuang.IndexOf("#") < 0 ? "0#0#0" : fd.RuShouShuShi.PiFuQingKuang;
                        string[] ru_pfqkArray = ru_pfqk.Split('#');
                        if (ru_pfqkArray.Length >= 3)
                        {
                            newRow["Ru_PFQK1"] = ru_pfqkArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_PFQK2"] = ru_pfqkArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["Ru_PFQK3"] = ru_pfqkArray[2].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    newRow["Ru_PFQKMC"] = fd.RuShouShuShi.PFQK_NeiRong;
                    if (!string.IsNullOrEmpty(fd.RuShouShuShi.HuanZheQuXiang))
                    {
                        newRow["Ru_HZQX1"] = fd.RuShouShuShi.HuanZheQuXiang.Equals("0") ? theTrue : string.Empty;
                        newRow["Ru_HZQX2"] = fd.RuShouShuShi.HuanZheQuXiang.Equals("1") ? theTrue : string.Empty;
                        newRow["Ru_HZQX3"] = fd.RuShouShuShi.HuanZheQuXiang.Equals("2") ? theTrue : string.Empty;
                    }
                    newRow["Ru_HSQM"] = fd.RuShouShuShi.HuShiQianMing;
                    newRow["Ru_SSSHSQM"] = fd.RuShouShuShi.ShouShuShiHuShiQianMing;

                    if (!string.IsNullOrEmpty(fd.ChuShouShuShi.YiShi))
                    {
                        newRow["Chu_YiShi1"] = fd.ChuShouShuShi.YiShi.Equals("0") ? theTrue : string.Empty;
                        newRow["Chu_YiShi2"] = fd.ChuShouShuShi.YiShi.Equals("1") ? theTrue : string.Empty;
                        newRow["Chu_YiShi3"] = fd.ChuShouShuShi.YiShi.Equals("2") ? theTrue : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(fd.ChuShouShuShi.WanDai))
                    {
                        newRow["Chu_WanDai1"] = fd.ChuShouShuShi.WanDai.Equals("0") ? theTrue : string.Empty;
                        newRow["Chu_WanDai2"] = fd.ChuShouShuShi.WanDai.Equals("1") ? theTrue : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(fd.ChuShouShuShi.XieDaiWuPin))
                    {
                        string chu_xdwp = fd.ChuShouShuShi.XieDaiWuPin.IndexOf("#") < 0 ? "0#0#0#0" : fd.ChuShouShuShi.XieDaiWuPin;
                        string[] chu_xdwpArray = chu_xdwp.Split('#');
                        if (chu_xdwpArray.Length >= 4)
                        {
                            newRow["Chu_XDWP1"] = chu_xdwpArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_XDWP2"] = chu_xdwpArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_XDWP3"] = chu_xdwpArray[2].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_XDWP4"] = chu_xdwpArray[3].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    newRow["Chu_XDWPMC"] = fd.ChuShouShuShi.XDWP_QiTa;
                    if (!string.IsNullOrEmpty(fd.ChuShouShuShi.SuiShenShiWu))
                    {
                        newRow["Chu_SSSW1"] = fd.ChuShouShuShi.SuiShenShiWu.Equals("0") ? theTrue : string.Empty;
                        newRow["Chu_SSSW2"] = fd.ChuShouShuShi.SuiShenShiWu.Equals("1") ? theTrue : string.Empty;
                    }
                    newRow["Chu_SSSWMC"] = fd.ChuShouShuShi.SSSW_MingCheng;
                    newRow["Chu_SSSWJS"] = fd.ChuShouShuShi.SSSW_JianShu;
                    newRow["Chu_XueZiPin1"] = fd.ChuShouShuShi.XueZhiPin.Equals("0") ? theTrue : string.Empty;
                    newRow["Chu_XueZiPin2"] = fd.ChuShouShuShi.XueZhiPin.Equals("1") ? theTrue : string.Empty;
                    newRow["Chu_XueZiPinMC"] = fd.ChuShouShuShi.XZP_MingChengDaiShu;
                    if (!string.IsNullOrEmpty(fd.ChuShouShuShi.JingMaiTongLu))
                    {
                        string chu_jmtl = fd.ChuShouShuShi.JingMaiTongLu.IndexOf("#") < 0 ? "0#0#0#0#0" : fd.ChuShouShuShi.JingMaiTongLu;
                        string[] chu_jmtlArray = chu_jmtl.Split('#');
                        if (chu_jmtlArray.Length >= 4)
                        {
                            newRow["Chu_JMTL1"] = chu_jmtlArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_JMTL2"] = chu_jmtlArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_JMTL3"] = chu_jmtlArray[2].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_JMTL4"] = chu_jmtlArray[3].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_JMTL5"] = chu_jmtlArray[4].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    if (!string.IsNullOrEmpty(fd.ChuShouShuShi.ShuHouLiuZhi))
                    {
                        string chu_sslz = fd.ChuShouShuShi.ShuHouLiuZhi.IndexOf("#") < 0 ? "0#0#0#0#0" : fd.ChuShouShuShi.ShuHouLiuZhi;
                        string[] chu_sslzArray = chu_sslz.Split('#');
                        if (chu_sslzArray.Length >= 4)
                        {
                            newRow["Chu_SHLZ1"] = chu_sslzArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_SHLZ2"] = chu_sslzArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_SHLZ3"] = chu_sslzArray[2].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_SHLZ4"] = chu_sslzArray[3].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_SHLZ5"] = chu_sslzArray[4].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    newRow["Chu_SHLZMC"] = fd.ChuShouShuShi.SHLZ_QiTa;
                    if (!string.IsNullOrEmpty(fd.ChuShouShuShi.PiFuQingKuang))
                    {
                        string chu_pfqk = fd.ChuShouShuShi.PiFuQingKuang.IndexOf("#") < 0 ? "0#0#0" : fd.ChuShouShuShi.PiFuQingKuang;
                        string[] chu_pfqkArray = chu_pfqk.Split('#');
                        if (chu_pfqkArray.Length >= 3)
                        {
                            newRow["Chu_PFQK1"] = chu_pfqkArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_PFQK2"] = chu_pfqkArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["Chu_PFQK3"] = chu_pfqkArray[2].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    newRow["Chu_PFQKMC"] = fd.ChuShouShuShi.PFQK_NeiRong;
                    newRow["Chu_HZQX1"] = fd.ChuShouShuShi.HuanZheQuXiang.Equals("0") ? theTrue : string.Empty;
                    newRow["Chu_HZQX2"] = fd.ChuShouShuShi.HuanZheQuXiang.Equals("1") ? theTrue : string.Empty;
                    newRow["Chu_HZQX3"] = fd.ChuShouShuShi.HuanZheQuXiang.Equals("2") ? theTrue : string.Empty;
                    newRow["Chu_SSSHSQM"] = fd.ChuShouShuShi.ShouShuShiHuShiQianMing;
                    newRow["Chu_HSQM"] = fd.ChuShouShuShi.HuShiQianMing;

                    newRow["PACU_YiShi1"] = fd.ChuPACU.YiShi.Equals("0") ? theTrue : string.Empty;
                    newRow["PACU_YiShi2"] = fd.ChuPACU.YiShi.Equals("1") ? theTrue : string.Empty;
                    newRow["PACU_YiShi3"] = fd.ChuPACU.YiShi.Equals("2") ? theTrue : string.Empty;
                    newRow["PACU_MaiBo"] = fd.ChuPACU.MaiBo;
                    newRow["PACU_XueYa1"] = fd.ChuPACU.XueYa.Split('/')[0];
                    newRow["PACU_XueYa2"] = fd.ChuPACU.XueYa.Split('/')[1];
                    newRow["PACU_XYBHD"] = fd.ChuPACU.XueYangBaoHeDu;
                    newRow["PACU_WanDai1"] = fd.ChuPACU.WanDai.Equals("0") ? theTrue : string.Empty;
                    newRow["PACU_WanDai2"] = fd.ChuPACU.WanDai.Equals("1") ? theTrue : string.Empty;
                    if (!string.IsNullOrEmpty(fd.ChuPACU.XieDaiWuPin))
                    {
                        string pacu_xdwp = fd.ChuPACU.XieDaiWuPin.IndexOf("#") < 0 ? "0#0#0#0" : fd.ChuPACU.XieDaiWuPin;
                        string[] pacu_xdwpArray = pacu_xdwp.Split('#');
                        if (pacu_xdwpArray.Length >= 4)
                        {
                            newRow["PACU_XDWP1"] = pacu_xdwpArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_XDWP2"] = pacu_xdwpArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_XDWP3"] = pacu_xdwpArray[2].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_XDWP4"] = pacu_xdwpArray[3].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    newRow["PACU_XDWPMC"] = fd.ChuPACU.XDWP_QiTa;
                    newRow["PACU_SSSW1"] = fd.ChuPACU.SuiShenShiWu.Equals("0") ? theTrue : string.Empty;
                    newRow["PACU_SSSW2"] = fd.ChuPACU.SuiShenShiWu.Equals("1") ? theTrue : string.Empty;
                    newRow["PACU_SSSWMC"] = fd.ChuPACU.SSSW_MingCheng;
                    newRow["PACU_SSSWJS"] = fd.ChuPACU.SSSW_JianShu;
                    newRow["PACU_XueZiPin1"] = fd.ChuPACU.XueZhiPin.Equals("0") ? theTrue : string.Empty;
                    newRow["PACU_XueZiPin2"] = fd.ChuPACU.XueZhiPin.Equals("1") ? theTrue : string.Empty;
                    newRow["PACU_XueZiPinMC"] = fd.ChuPACU.XZP_MingChengDaiShu;
                    if (!string.IsNullOrEmpty(fd.ChuPACU.JingMaiTongLu))
                    {
                        string pacu_jmtl = fd.ChuPACU.JingMaiTongLu.IndexOf("#") < 0 ? "0#0#0#0#0" : fd.ChuShouShuShi.ShuHouLiuZhi;
                        string[] pacu_jmtlArray = pacu_jmtl.Split('#');
                        if (pacu_jmtlArray.Length >= 5)
                        {
                            newRow["PACU_JMTL1"] = pacu_jmtlArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_JMTL2"] = pacu_jmtlArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_JMTL3"] = pacu_jmtlArray[2].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_JMTL4"] = pacu_jmtlArray[3].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_JMTL5"] = pacu_jmtlArray[4].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    newRow["PACU_PCABeng1"] = fd.ChuPACU.PCA_Beng.Equals("0") ? theTrue : string.Empty;
                    newRow["PACU_PCABeng2"] = fd.ChuPACU.PCA_Beng.Equals("1") ? theTrue : string.Empty;
                    newRow["PACU_PCABengTJ1"] = fd.ChuPACU.PCA_BengTuJing.Equals("0") ? theTrue : string.Empty;
                    newRow["PACU_PCABengTJ2"] = fd.ChuPACU.PCA_BengTuJing.Equals("1") ? theTrue : string.Empty;
                    if (!string.IsNullOrEmpty(fd.ChuPACU.ShuHouLiuZhi))
                    {
                        string pacu_shlz = fd.ChuPACU.ShuHouLiuZhi.IndexOf("#") < 0 ? "0#0#0" : fd.ChuShouShuShi.ShuHouLiuZhi;
                        string[] pacu_shlzArray = pacu_shlz.Split('#');
                        if (pacu_shlzArray.Length >= 5)
                        {
                            newRow["PACU_SHLZ1"] = pacu_shlzArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_SHLZ2"] = pacu_shlzArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_SHLZ3"] = pacu_shlzArray[2].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    newRow["PACU_SHLZMC"] = fd.ChuPACU.SHLZ_NeiRong;
                    if (!string.IsNullOrEmpty(fd.ChuPACU.PiFuQingKuang))
                    {
                        string pacu_pfqk = fd.ChuPACU.PiFuQingKuang.IndexOf("#") < 0 ? "0#0#0" : fd.ChuShouShuShi.PiFuQingKuang;
                        string[] pacu_pfqkArray = pacu_pfqk.Split('#');
                        if (pacu_pfqkArray.Length >= 5)
                        {
                            newRow["PACU_PFQK1"] = pacu_pfqkArray[0].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_PFQK2"] = pacu_pfqkArray[1].Equals("1") ? theTrue : string.Empty;
                            newRow["PACU_PFQK3"] = pacu_pfqkArray[2].Equals("1") ? theTrue : string.Empty;
                        }
                    }
                    newRow["PACU_PFQKMC"] = fd.ChuPACU.PFQK_NeiRong;
                    newRow["PACU_HZQX1"] = fd.ChuPACU.HuanZheQuXiang.Equals("0") ? theTrue : string.Empty;
                    newRow["PACU_HZQX2"] = fd.ChuPACU.HuanZheQuXiang.Equals("1") ? theTrue : string.Empty;
                    newRow["PACU_PACUYSQM"] = fd.ChuPACU.PACU_YiShiQianMing;
                    newRow["PACU_HSQM"] = fd.ChuPACU.HuShiQianMing;
                    newRow["Ru_JieBingRenShiJian"] = fd.RuShouShuShi.JieBingRenShiJian;
                    newRow["Chu_ChuShouShuShiShiJian"] = fd.ChuShouShuShi.ChuShouShuShiShiJian;
                    newRow["PACU_ChuPACUShiJain"] = fd.ChuPACU.ChuPACU_ShiJian;


                    newRow["RiQi"] = string.IsNullOrEmpty(fd.RiQi) ? string.Empty : Convert.ToDateTime(fd.RiQi).ToString("yyyy-MM-dd");
                    //ID隐藏，双击触发事件
                    newRow["Id"] = dr["ID"];
                    dtt.Rows.Add(newRow);
                }
            }
            gridControl1.DataSource = dtt;
        }

        private void SetBandGridView()
        {
            foreach (GridBand gridBand in this.bandedGridView1.Bands)//设置居中
            {
                foreach (GridBand gridBandSecond in gridBand.Children)
                {
                    gridBandSecond.OptionsBand.FixedWidth = true;
                    gridBandSecond.AppearanceHeader.Options.UseTextOptions = true;
                    gridBandSecond.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                    gridBandSecond.AppearanceHeader.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;
                }
                gridBand.OptionsBand.FixedWidth = true;
                gridBand.AppearanceHeader.Options.UseTextOptions = true;
                gridBand.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                gridBand.AppearanceHeader.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;
            }
        }

        #region  查询
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string StatDate = this.dateStart.Text;
            string EndDate = this.dateEnd.Text;

            if (string.IsNullOrEmpty(StatDate) || string.IsNullOrEmpty(EndDate))
            {
                MessageBox.Show("查询日期不能为空！");
            }
            LoadData(StatDate, EndDate);
        }
        #endregion

        #region 新增
        private void btnAdd_Click(object sender, EventArgs e)
        {
            HandoverSing addForm = new HandoverSing(user, patientinfo, string.Empty);
            addForm.ShowDialog();
            if (addForm.DialogResult == DialogResult.OK)
            {
                LoadData("", "");
            }
        }
        #endregion

        #region 修改
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (bandedGridView1.RowCount > 0)
            {
                string Id = bandedGridView1.GetRowCellValue(bandedGridView1.FocusedRowHandle, "Id").ToString();
                HandoverSing addForm = new HandoverSing(user, patientinfo, Id);
                addForm.ShowDialog();
                if (addForm.DialogResult == DialogResult.OK)
                {
                    LoadData("", "");
                }
            }
        }
        #endregion

        #region 打印
        private void btnPrint_Click(object sender, EventArgs e)
        {
            string patientId = patientinfo[0];
            string visit = patientinfo[1];
            //单张打印
            //HandoverPrint f = new HandoverPrint(patientId, Convert.ToInt32(visit), (int)FormType.Knowing);
            //多张打印
            HandoverPrints f = new HandoverPrints(patientinfo, (int)FormType.PatientHandover, dateStart.DateTime, dateEnd.DateTime, string.Empty);
            f.Show();
        }
        #endregion

        #region 删除
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要删除数据吗？", "删除前确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                string id = bandedGridView1.GetRowCellValue(bandedGridView1.FocusedRowHandle, "Id").ToString();
                var ret2 = formService.DeleteNursingFormRecord(id);
                MessageBox.Show(ret2.M);
                if (ret2.Code == 1)
                {
                    string dateStart = this.dateStart.Text;
                    string dateEnd = this.dateEnd.Text;
                    LoadData(dateStart, dateEnd);
                }
            }
        }
        #endregion

        #region 开始时间
        private void dateStart_EditValueChanged(object sender, EventArgs e)
        {
            btnSearch_Click(null, null);
        }
        #endregion

        #region 结束时间
        private void dateEnd_EditValueChanged(object sender, EventArgs e)
        {
            btnSearch_Click(null, null);
        }
        #endregion

        private void bandedGridView1_DoubleClick(object sender, EventArgs e)
        {
            if (bandedGridView1.RowCount > 0)
            {
                string Id = bandedGridView1.GetRowCellValue(bandedGridView1.FocusedRowHandle, "Id").ToString();
                HandoverSing addForm = new HandoverSing(user, patientinfo, Id);
                addForm.ShowDialog();
                if (addForm.DialogResult == DialogResult.OK)
                {
                    LoadData("", "");
                }
            }
        }
    }
}
